package com.hhkj.admin.order.common.component.validator;

import com.hhkj.admin.course.domain.Course;
import com.hhkj.admin.order.common.exception.InvalidOrderItemException;
import com.hhkj.admin.order.domain.OrderItem;
import lombok.AllArgsConstructor;
import lombok.Data;

import java.util.List;
import java.util.Map;

@AllArgsConstructor
@Data
public class SysCourseValidatorStrategy extends BaseOrderItemValidateStrategy{

    /** （科目名称-科目信息）map映射表 **/
    private Map<String, List<Course>> courseNameMap;

    /**
     * 校验科目名称
     * @param orderItem
     * @return
     * @throws InvalidOrderItemException
     */
    @Override
    public boolean validate(OrderItem orderItem) throws InvalidOrderItemException {
        List<Course> courseList = courseNameMap.get(orderItem.getCourseName());
        Long courseId = OrderItemValidator.isValidCourse(orderItem, courseList);
        orderItem.setCourseId(courseId);
        return true;
    }
}
